interface DictItem {
  label: string;
  value: string;
}

interface DictType {
  [key: string]: {
    [key: string]: DictItem;
  };
}

import dict from '@/constants/dictionary'

/**
 * 根据字典类型和值获取标签
 * @param dictType 字典类型
 * @param value 值
 * @returns 对应的标签
 */
export function getDictLabel(dictType: string, value: string | number): string {
  const dictData = dict[dictType as keyof typeof dict]
  if (!dictData) return '未知'
  
  const found = Object.values(dictData).find(item => item.value === String(value))
  return found ? found.label : '未知'
}

/**
 * 根据字典类型获取字典列表
 * @param dictType 字典类型
 * @returns 字典列表
 */
export function getDictList(dictType: string): Array<DictItem> {
  const dictData = dict[dictType as keyof typeof dict]
  if (!dictData) return []
  
  return Object.values(dictData)
}

/**
 * 根据字典类型和标签获取值
 * @param dictType 字典类型
 * @param label 标签
 * @returns 对应的值
 */
export function getDictValue(dictType: string, label: string): string {
  const dictData = dict[dictType as keyof typeof dict]
  if (!dictData) return ''
  
  const found = Object.values(dictData).find(item => item.label === label)
  return found ? found.value : ''
} 